<?php include(TPL_PATH . '/admin/inc_header.php'); ?>
<?php include(TPL_PATH . '/admin/inc_top.php'); ?>

<link rel="stylesheet" href="<?php p(HTTP_URL) ?>/statics/kindeditor/themes/default/default.css" />
<script type="text/javascript" src="<?php p(HTTP_URL) ?>/statics/kindeditor/kindeditor.js"></script>
<script type="text/javascript">

$(document).ready(function() {
	$('input[type=text]').tooltip({'placement':'right'});
	var btnUp = KindEditor.uploadbutton({
		'button' : $('#id_upbtn')[0],
		'fieldName' : 'img_file',
		'url' : '<?php p(HTTP_URL) ?>/index.php?m=admin&c=file&a=upload',
		'afterUpload' : function(data) {
			if (data.error === 0) {
				show_thumb(data.url);
			} else {
				alert(data.message);
			}
		}
	});
	btnUp.fileBox.change(function(e) {
		btnUp.submit();
	});
	$('.cls_order').each(function() {
		$(this).blur(function() {
			var _this = $(this);
			var v = _this.val();
			var id = _this.attr('id');
			if ('' != v) {
				$.post('<?php p(HTTP_URL) ?>/index.php?m=admin&c=content&a=sort_page', {"id":id, "val":v}, function(re) {
					if ('no' == re.ok) {
						alert(re.msg);
					} else if ('yes' == re.ok) {
						$('#' + id).attr('placeholder', v);
					}
					$('#' + id).val('');
				}, 'json');
			}
		});
	});
});
function do_clean(id) {
	if (confirm('删除后不可还原,确定删除吗?')) {
		window.location.href = '<?php p(HTTP_URL) ?>/index.php?m=admin&c=content&a=clean&id=' + id;
	}
}
function show_thumb(path) {
	$('.up_a').show().eq(0).attr('href', '<?php p(HTTP_URL) ?>' + path);
	$('.up_a').eq(1).attr('href', '<?php p(HTTP_URL) ?>/index.php?m=admin&c=file&a=cut&callback=show_thumb&w=200&h=200&path=' + path);
	$('#id_thumb').val(path);
	var img = $('#id_show_thumb');
	img.attr('src', '<?php p(HTTP_URL) ?>' + path + '?' + (new Date).getTime());
	img.show();
}

function del_up() {
	if (confirm('确定删除?')) {
    	$('.up_a').hide().eq(0).attr('href', '#');
    	$('.up_a').eq(1).attr('href', '#');
    	$('#id_thumb').val('');
    	var img = $('#id_show_thumb');
    	img.attr('src', '');
    	img.hide();
	}
}
</script>

<form action="<?php p(HTTP_URL); ?>/index.php?m=admin&c=content&a=<?php if ($blnAdd) { ?>add<?php } else { ?>edit&id=<?php p($id); } ?>" method="post">
    <fieldset>
    	<legend>内容<?php (!$blnAdd) ? p(' - ' . $arrData['title']) : p(' - 添加新内容') ?></legend>
    	
    	<?php if (!empty($strMsg)) { ?>
		<div class="alert alert-error">
			<button type="button" class="close" data-dismiss="alert">&times;</button>
			<?php p($strMsg) ?>
		</div>
		<?php } elseif (!empty($strOk)) { ?>
    	<div class="alert alert-success">
			<button type="button" class="close" data-dismiss="alert">&times;</button>
			<?php p($strOk) ?>
		</div>
    	<?php } ?>
    	
    	<label for="id_cat_id">关联栏目</label>
    	<?php p($objTreeList->getSelect('cat_id', (isset($arrData['cat_id']) ? $arrData['cat_id'] : 0), false, 'class="input-xxlarge"', array(0, '暂未确定栏目'))) ?>
        <label for="id_title">标题</label>
    	<input type="text" class="input-xxlarge" name="title" id="id_title" value="<?php p($arrData['title']) ?>" title="必填项,80字以内" />
    	<label for="id_source">来源</label>
    	<input type="text" class="input-xxlarge" name="source_from" id="id_source" value="<?php p($arrData['source_from']) ?>" title="80字以内" />
        <label for="id_upbtn">主图</label>
        <input type="hidden" id="id_thumb" name="thumb" value="<?php p($arrData['thumb']) ?>" />
        <input type="button" id="id_upbtn" value="上传" />
        <a href="<?php p($arrData['thumb'] ? HTTP_URL . $arrData['thumb'] : '#') ?>" target="_blank" class="btn up_a" <?php !$arrData['thumb'] && p('style="display:none;"') ?>>原图</a>
        <a href="<?php p($arrData['thumb'] ? HTTP_URL . '/index.php?m=admin&c=file&a=cut&callback=show_thumb&w=200&h=200&path=' . $arrData['thumb'] : '#') ?>" target="_blank" class="btn up_a" <?php !$arrData['thumb'] && p('style="display:none;"') ?>>裁剪</a>
        <a href="javascript:del_up();" class="btn up_a" <?php !$arrData['thumb'] && p('style="display:none;"') ?>>删除</a>
        <br /><br />
        <img alt="" src="<?php p($arrData['thumb'] ? HTTP_URL . $arrData['thumb'] . '?' . time() : '') ?>" id="id_show_thumb" style="<?php !$arrData['thumb'] && p('display:none; ') ?>width:200px; height:200px;" class="img-polaroid" />
        <br /><br />
        <label for="id_desc">描述</label>
    	<textarea name="desc" class="input-xxlarge" id="id_desc"><?php p($arrData['desc']) ?></textarea>
    	<label for="id_tags">标签</label>
    	<input type="text" class="input-xxlarge" name="tags" id="id_tags" value="<?php p($arrData['tags']) ?>" title="以空格分开" />
        <label for="id_seo_t">SEO Title</label>
    	<input type="text" class="input-xxlarge" name="seo_t" id="id_seo_t" value="<?php p($arrData['seo_t']) ?>" title="80字以内" />
    	<label for="id_seo_k">SEO Keyword</label>
    	<input type="text" class="input-xxlarge" name="seo_k" id="id_seo_k" value="<?php p($arrData['seo_k']) ?>" title="80字以内" />
    	<label for="id_seo_d">SEO Description</label>
    	<textarea name="seo_d" class="input-xxlarge" id="id_seo_d"><?php p($arrData['seo_d']) ?></textarea>
    	<?php if (!$blnAdd) { ?>
        <label class="checkbox">
            <input name="rec_status" type="checkbox" <?php if ($arrData['rec_status']) { ?>checked="checked"<?php } ?> value="1" /> 上线状态
        </label>
        <?php } ?>
        <br />
        <input type="submit" class="btn btn-primary" name="sub_btn" value="<?php $blnAdd ? p('添加内容') : p('保存修改') ?>" />
        <?php if (!$blnAdd) { ?>
        <a class="btn btn-danger" href="javascript:do_clean(<?php p($id) ?>);">删除</a>
        <?php } ?>
        <a href="<?php p(HTTP_URL) ?>/index.php?m=admin&c=content" class="btn">返回列表</a>
    </fieldset>
</form>
<?php if (!$blnAdd) { ?>
<table class="table table-bordered table-condensed" width="100%" cellspacing="0" cellpadding="0">
	<tr>
		<td colspan="7">
			<ul class="breadcrumb" style="margin:0px;">
				<li>内容页列表</li>
			</ul>
		</td>
	</tr>
	<tr>
		<th style="width:30px;">ID</th>
		<th>标题</th>
		<th style="width:75px;">排序</th>
		<th style="width:31px;">状态</th>
		<th style="width:116px;">最近修改</th>
		<th style="width:116px;">创建时间</th>
		<th style="width:55px;">编辑</th>
	</tr>
	<?php foreach ($arrPageList as $arrTemp) { ?>
	<tr>
		<td><?php p($arrTemp['id']) ?></td>
		<td><?php p($arrTemp['title']) ?></td>
		<td><input style="margin-bottom:0px;" type="text" id="id_<?php p($arrTemp['id']) ?>" placeholder="<?php p($arrTemp['list_order']) ?>" value="" class="cls_order input-mini" title="正整数,较小的排序在前,即时保存"></td>
		<td><i class="icon-<?php ($arrTemp['rec_status']) ? p('ok') : p('remove'); ?>"></i></td>
		<td><small><?php p($arrTemp['last_updated']) ?></small></td>
		<td><small><?php p($arrTemp['created_at']) ?></small></td>
		<td><a target="_blank" href="<?php p(HTTP_URL) ?>/index.php?m=admin&c=content&a=edit_page&content_id=<?php p($id) ?>&page_id=<?php p($arrTemp['id']) ?>" class="btn">编辑</a></td>
	</tr>
	<?php } ?>
	<tr>
		<td colspan="7" style="text-align:center;">
			<a target="_blank" class="btn btn-primary" href="<?php p(HTTP_URL) ?>/index.php?m=admin&c=content&a=add_page&content_id=<?php p($id) ?>">添加新内容页</a>
			<!--
    		<div class="btn-group">
                <button class="btn btn-primary dropdown-toggle" data-toggle="dropdown">添加内容页 <span class="caret"></span></button>
                <ul class="dropdown-menu">
                  <li><a target="_blank" href="<?php p(HTTP_URL) ?>/index.php?m=admin&c=content&a=add_page&content_id=<?php p($id) ?>">按默认模型添加</a></li>
                </ul>
            </div>
            -->
		</td>
	</tr>
</table>
<?php } ?>
<?php include(TPL_PATH . '/admin/inc_bottom.php'); ?>
<?php include(TPL_PATH . '/admin/inc_footer.php'); ?>